package grafica.jugador.ventanas;

import grafica.jugador.controladores.ControladorAtacar;
import grafica.jugador.controladores.ControladorJugador;

import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JButton;


import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Dimension;

public class Atacar {

	private JDialog jDialogAtacar = null;  //  @jve:decl-index=0:visual-constraint="91,31"
	private JPanel jContentPaneAtacar = null;
	private JPanel jPanelAtacar = null;
	private JButton jButtonAceptar = null;
	private JButton jButtonCancelar = null;
	private JLabel jLabelInfo = null;
	private ControladorAtacar controladorAtacar;
	private String nomPais1;
	private String nomPais2;
	private String nomJugador;
	private JPanel jPanelTitulo = null;
	private JLabel jLabel = null;
	private JPanel jPanelDadoAtaque = null;
	private JPanel jPanelDadoDefensa = null;
	private JLabel jLabelDadoAtaque = null;
	private JLabel jLabelDadoDefensa = null;
	private JPanel jPanelImgDadoAtaque = null;
	private JPanel jPanelImgDadoDefensa = null;
	private AnimacionDados animAtaque = null;
	private AnimacionDados animDefensa = null;
	
	public Atacar(String nomPais1, String nomPais2, String nomJugador, ControladorJugador controladorJugador){
		controladorAtacar = new ControladorAtacar(this,controladorJugador);
		this.nomPais1 = nomPais1;
		this.nomPais2 = nomPais2;
		this.nomJugador = nomJugador;
	}
	/**
	 * This method initializes jDialogAtacar	
	 * 	
	 * @return javax.swing.JDialog	
	 */
	private JDialog getJDialogAtacar() {
		if (jDialogAtacar == null) {
			jDialogAtacar = new JDialog();
			jDialogAtacar.setSize(new java.awt.Dimension(332,274));
			jDialogAtacar.setResizable(false);
			jDialogAtacar.setContentPane(getJContentPaneAtacar());
			jDialogAtacar.setTitle("Atacar desde "+nomPais1+" a "+nomPais2);
			jDialogAtacar.setLocationRelativeTo(null);
		}
		return jDialogAtacar;
	}

	/**
	 * This method initializes jContentPaneAtacar	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJContentPaneAtacar() {
		if (jContentPaneAtacar == null) {
			jContentPaneAtacar = new JPanel();
			jContentPaneAtacar.setLayout(new BorderLayout());
			jContentPaneAtacar.add(getJPanelAtacar(), java.awt.BorderLayout.SOUTH);
			jContentPaneAtacar.add(getJPanelTitulo(), java.awt.BorderLayout.NORTH);
			jContentPaneAtacar.add(getJPanelDadoAtaque(), java.awt.BorderLayout.WEST);
			jContentPaneAtacar.add(getJPanelDadoDefensa(), java.awt.BorderLayout.EAST);
		}
		return jContentPaneAtacar;
	}

	/**
	 * This method initializes jPanelAtacar	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelAtacar() {
		if (jPanelAtacar == null) {
			FlowLayout flowLayout = new FlowLayout();
			flowLayout.setHgap(25);
			flowLayout.setVgap(15);
			jLabelInfo = new JLabel();
			jLabelInfo.setText("");
			jLabelInfo.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
			jLabelInfo.setPreferredSize(new java.awt.Dimension(320,25));
			jPanelAtacar = new JPanel();
			jPanelAtacar.setLayout(flowLayout);
			jPanelAtacar.setPreferredSize(new java.awt.Dimension(200,85));
			jPanelAtacar.add(getJButtonAceptar(), null);
			jPanelAtacar.add(getJButtonCancelar(), null);
			jPanelAtacar.add(jLabelInfo, null);
		}
		return jPanelAtacar;
	}

	/**
	 * This method initializes jButtonAceptar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonAceptar() {
		if (jButtonAceptar == null) {
			jButtonAceptar = new JButton();
			jButtonAceptar.setPreferredSize(new java.awt.Dimension(90,25));
			jButtonAceptar.setText("Atacar");
			ActionListener BotonAceptar = new ActionListener(){
				public void actionPerformed (ActionEvent e){	
					jButtonAceptar.setEnabled(false);
					jButtonCancelar.setEnabled(false);
					controladorAtacar.RealizarAtaque(nomJugador, nomPais1 , nomPais2);
				}
			};
			jButtonAceptar.addActionListener(BotonAceptar);			 
		}
		return jButtonAceptar;
	}

	/**
	 * This method initializes jButtonCancelar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonCancelar() {
		if (jButtonCancelar == null) {
			jButtonCancelar = new JButton();
			jButtonCancelar.setPreferredSize(new java.awt.Dimension(90,25));
			jButtonCancelar.setText("Retirarse");
			ActionListener BotonCancelar = new ActionListener(){
				public void actionPerformed (ActionEvent e){ 
					jDialogAtacar.dispose(); 
				}
			};
			jButtonCancelar.addActionListener(BotonCancelar );  
		}
		return jButtonCancelar;
	}
	public void setVisible (boolean b)	{	
		getJDialogAtacar().setVisible(b);
    }
	public void setJLabelInfo(String info){
		jLabelInfo.setText(info);
	}
	public void cerrarVentana(){
		jDialogAtacar.dispose();  
	}
	/**
	 * This method initializes jPanelTitulo	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelTitulo() {
		if (jPanelTitulo == null) {
			jLabel = new JLabel();
			jLabel.setPreferredSize(new Dimension(250, 16));
			jLabel.setText("Atacar de " + nomPais1 + " a "+ nomPais2);
			jPanelTitulo = new JPanel();
			jPanelTitulo.add(jLabel, null);
		}
		return jPanelTitulo;
	}
	/**
	 * This method initializes jPanelDadoAtaque	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelDadoAtaque() {
		if (jPanelDadoAtaque == null) {
			jLabelDadoAtaque = new JLabel();
			jLabelDadoAtaque.setText("Ataque");
			jPanelDadoAtaque = new JPanel();
			jPanelDadoAtaque.setPreferredSize(new java.awt.Dimension(130,140));
			jPanelDadoAtaque.add(jLabelDadoAtaque, null);
			jPanelDadoAtaque.add(getJPanelImgDadoAtaque(), null);
		}
		return jPanelDadoAtaque;
	}
	/**
	 * This method initializes jPanelDadoDefensa	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelDadoDefensa() {
		if (jPanelDadoDefensa == null) {
			jLabelDadoDefensa = new JLabel();
			jLabelDadoDefensa.setText("Defensa");
			jPanelDadoDefensa = new JPanel();
			jPanelDadoDefensa.setPreferredSize(new java.awt.Dimension(130,10));
			jPanelDadoDefensa.add(jLabelDadoDefensa, null);
			jPanelDadoDefensa.add(getJPanelImgDadoDefensa(), null);
		}
		return jPanelDadoDefensa;
	}
	/**
	 * This method initializes jPanelImgDadoAtaque	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelImgDadoAtaque() {
		if (jPanelImgDadoAtaque == null) {
			jPanelImgDadoAtaque = new JPanel();
			jPanelImgDadoAtaque.setPreferredSize(new java.awt.Dimension(120,100));
			animAtaque = new AnimacionDados(jPanelImgDadoAtaque.getSize(),this);        
			jPanelImgDadoAtaque.add(animAtaque);
			jPanelImgDadoAtaque.repaint();
		}
		return jPanelImgDadoAtaque;
	}
	/**
	 * This method initializes jPanelImgDadoDefensa	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelImgDadoDefensa() {
		if (jPanelImgDadoDefensa == null) {
			jPanelImgDadoDefensa = new JPanel();
			jPanelImgDadoDefensa.setPreferredSize(new java.awt.Dimension(120,100));
			animDefensa = new AnimacionDados(jPanelImgDadoDefensa.getSize(),this);        
			jPanelImgDadoDefensa.add(animDefensa);
			jPanelImgDadoDefensa.repaint();
		}
		return jPanelImgDadoDefensa;
	}	
	
	public void iniciarAnimacion(int ataque, int defensa){
		animAtaque.startAnimation(ataque);
		animDefensa.startAnimation(defensa);
	}
	
	public void habilitarBotones(){
		jButtonAceptar.setEnabled(true);
		jButtonCancelar.setEnabled(true);
	}
	
	public void deshabilitarBoton(){
		jButtonAceptar.setEnabled(false);
	}
	
	public ControladorAtacar getControladorAtacar(){
		return controladorAtacar;
	}
}
